//
//  GYMineOrderInfoDetailVC.m
//  GYDemo
//
//  Created by mac on 2018/4/4.
//  Copyright © 2018年 mac. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "GYMineOrderInfoDetailVC.h"
#import "Head.h"

@interface GYMineOrderInfoDetailFootView : UIView
@property (nonatomic,strong) GYMineOrderInfoDetailModel *dataModel;
///0 采购订单   1 销售订单
@property (nonatomic,strong) NSString *orderCatagery;
@property (nonatomic,strong) UILabel *statusLB;
@property (nonatomic,strong) UILabel *totoalPriceLB;
@property (nonatomic,strong) UIView *sepV;
@property (nonatomic,strong) UILabel *contentLB;
@property (nonatomic,strong) UIButton *orderCopyBtn;
-(CGFloat)finalHeight;
@end

@implementation GYMineOrderInfoDetailFootView
#pragma mark - getter and setter
-(UILabel *)statusLB
{
    if (!_statusLB) {
        _statusLB = [UILabel new];
        _statusLB.x = WFCGFloatX(13);
        _statusLB.y = WFCGFloatY(12.5);
        _statusLB.width = WFCGFloatX(126);
        _statusLB.height = WFCGFloatY(20);
        _statusLB.font = SYSTEMFONT(14);
        _statusLB.textColor = Main_Color_Yellow;
    }
    return _statusLB;
}
-(UILabel *)totoalPriceLB
{
    if (!_totoalPriceLB) {
        _totoalPriceLB = [UILabel new];
        _totoalPriceLB.x = self.width - WFCGFloatX(200 + 13);
        _totoalPriceLB.width = WFCGFloatX(200);
        _totoalPriceLB.y = WFCGFloatY(12.5);
        _totoalPriceLB.height = WFCGFloatY(20);
        _totoalPriceLB.font = SYSTEMFONT(14);
        _totoalPriceLB.textColor = Main_Color_Black;
        _totoalPriceLB.textAlignment = NSTextAlignmentRight;
    }
    return _totoalPriceLB;
}
-(UIView *)sepV
{
    if (!_sepV) {
        _sepV = [UIView new];
        _sepV.width = self.width;
        _sepV.height = 5.0f;
        _sepV.backgroundColor = Main_Color_BG;
        _sepV.y = WFCGFloatY(53.5);
    }
    return _sepV;
}
-(UILabel *)contentLB
{
    if (!_contentLB) {
        _contentLB = [UILabel new];
        _contentLB.numberOfLines = 0;
        _contentLB.x = WFCGFloatX(13);
        _contentLB.y = WFCGFloatY(53 + 19);
        _contentLB.width = self.width - WFCGFloatX(26);
        _contentLB.height = WFCGFloatY(16.5);
        _contentLB.font = SYSTEMFONT(12);
        _contentLB.textColor = Main_Color_Gray;
    }
    return _contentLB;
}
-(UIButton *)orderCopyBtn
{
    if (!_orderCopyBtn) {
        _orderCopyBtn = [UIButton new];
        _orderCopyBtn.frame = WFCGRectMake(220, 53 + 17.5, 38, 18);
        _orderCopyBtn.backgroundColor = Main_Color_LightGray;
        [WFFunctions WFUIaddbordertoView:_orderCopyBtn radius:WFCGFloatY(2) width:0 color:nil];
        _orderCopyBtn.titleLabel.font = SYSTEMFONT(11);
        [_orderCopyBtn setTitle:@"复制" forState:UIControlStateNormal];
        [_orderCopyBtn setTitleColor:Main_Color_White forState:UIControlStateNormal];
        [_orderCopyBtn addTarget:self action:@selector(copyOrderTap:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _orderCopyBtn;
}
-(void)setDataModel:(GYMineOrderInfoDetailModel *)dataModel
{
    _dataModel = dataModel;
    GYMineOrderInfoDetailModel *info = _dataModel;
    _statusLB.text = info.statusName;
    _totoalPriceLB.text = [NSString stringWithFormat:@"总价：%ld元",info.amount];
    NSString *ordernums = [NSString stringWithFormat:@"订单号：%@",info.idField];
    NSString *dates = [NSString stringWithFormat:@"下单时间：%@",info.createtime];
    NSString *comments = [NSString stringWithFormat:@"给卖家留言：%@",[WFFunctions WFStrCheckEmpty:info.descriptionField]?@"":info.descriptionField];
    
    NSString *evalalueContents = [NSString stringWithFormat:@"评价内容：%@",info.evaluateRemark];
    NSString *evalvalues = [NSString stringWithFormat:@"评分：%@",info.evaluateGrade];
    
    NSString *cancelReason = [NSString stringWithFormat:@"取消原因：%@",info.cancelreason];
    
    NSString *contents = [NSString stringWithFormat:@"%@\n\n%@\n\n%@",ordernums,dates,comments];
    if (1 == info.transtatus.integerValue) {
        //已下单
    }else if (2 == info.transtatus.integerValue) {
        //已完成或已评价
        if (0 == info.evalflag.integerValue) {
            //未评价
        }else{
            //已评价
            contents = [NSString stringWithFormat:@"%@\n\n%@\n\n%@",contents,evalalueContents,evalvalues];
        }
    }else{
        //已经取消
        contents = [NSString stringWithFormat:@"%@\n\n%@",contents,cancelReason];
    }
    
    CGFloat contentHeight = [WFFunctions WFStrGetSize:contents width:self.contentLB.width font:self.contentLB.font].height;
    self.contentLB.height = contentHeight;
    self.contentLB.text = contents;
    
    self.height = self.contentLB.bottom + WFCGFloatY(10);
}
#pragma mark - event
-(void)copyOrderTap:(id)sender
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.dataModel.idField;
    [FTIndicator showToastMessage:@"复制成功!"];
}
#pragma mark - method
-(CGFloat)finalHeight
{
    return self.height;
}
#pragma mark - life
-(instancetype)init
{
    if (self = [super init]) {
        self.backgroundColor = Main_Color_White;
        self.width = WF_UI_VIEW_WIDTH;
        
        [self addSubview:self.statusLB];
        [self addSubview:self.totoalPriceLB];
        [self addSubview:self.sepV];
        [self addSubview:self.contentLB];
        [self addSubview:self.orderCopyBtn];
    }
    return self;
}
@end

@interface GYMineOrderInfoDetailVC ()<UITextViewDelegate,GYCancelOrderAlertViewDelegate>
@property (nonatomic,strong) GYMineOrderInfoDetailViewModel *viewModel;
@property (nonatomic,strong) UIView *operateV;
@property (nonatomic,strong) UIButton *cancelBtn;
@property (nonatomic,strong) UIButton *editBtn;
@property (nonatomic,strong) UIButton *confirmBtn;
@property (nonatomic,strong) UIButton *evalBtn;
@property (nonatomic,strong) NSString *cancelReason;
@property (nonatomic,strong) UIView *evalV;
@property (nonatomic,strong) HCSStarRatingView *starRatingView;
@property (nonatomic,strong) UITextView *evalReasonTV;
@property (nonatomic,assign) NSInteger evalValue;
@property (nonatomic,strong) NSString *evalContent;
@property (nonatomic, strong) GYCancelOrderAlertView *cancelAlertView;

@property (nonatomic,strong) GYMineOrderInfoDetailFootView *orderFooterV;

@end

@implementation GYMineOrderInfoDetailVC
#pragma mark - getter and setter
-(GYMineOrderInfoDetailViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [GYMineOrderInfoDetailViewModel new];
    }
    _viewModel.orderInfoModel = _orderInfoModel;
    return _viewModel;
}
-(UIView *)operateV
{
    if (!_operateV) {
        _operateV = [UIView new];
        _operateV.width = self.view.width;
        _operateV.height = WFCGFloatY(46.5);
        _operateV.y = WF_UI_VIEW_HEIGHT - self.bottomShelterHeight - _operateV.height;
        _operateV.backgroundColor = Main_Color_White;
        [WFFunctions WFUIaddBorderToView:_operateV top:YES left:NO bottom:NO right:NO borderColor:Main_Color_BG borderWidth:0.7f];
        [_operateV addSubview:self.cancelBtn];
        [_operateV addSubview:self.editBtn];
        [_operateV addSubview:self.confirmBtn];
        [_operateV addSubview:self.evalBtn];
        _operateV.hidden = YES;
    }
    return _operateV;
}
-(UIButton *)cancelBtn
{
    if (!_cancelBtn) {
        _cancelBtn = [UIButton new];
        _cancelBtn.width = WFCGFloatX(83.5);
        _cancelBtn.height = WFCGFloatY(25);
        _cancelBtn.x = self.view.width - WFCGFloatX(13 + 83.5);
        _cancelBtn.y = WFCGFloatY(11);
        [WFFunctions WFUIaddbordertoView:_cancelBtn radius:_cancelBtn.height / 2 width:0.7f color:Main_Color_Red];
        _cancelBtn.titleLabel.font = SYSTEMFONT(14);
        [_cancelBtn setTitleColor:Main_Color_Red forState:UIControlStateNormal];
        [_cancelBtn addTarget:self action:@selector(cancelBtnTap:) forControlEvents:UIControlEventTouchUpInside];
        [_cancelBtn setTitle:@"取消订单" forState:UIControlStateNormal];
    }
    return _cancelBtn;
}
-(UIButton *)editBtn
{
    if (!_editBtn) {
        _editBtn = [UIButton new];
        _editBtn.width = WFCGFloatX(83.5);
        _editBtn.height = WFCGFloatY(25);
        _editBtn.x = self.view.width - WFCGFloatX(13 + 83.5);
        _editBtn.y = WFCGFloatY(11);
        [WFFunctions WFUIaddbordertoView:_editBtn radius:_editBtn.height / 2 width:0.7f color:Main_Color_Black];
        _editBtn.titleLabel.font = SYSTEMFONT(14);
        [_editBtn setTitleColor:Main_Color_Black forState:UIControlStateNormal];
        [_editBtn addTarget:self action:@selector(editBtnTap:) forControlEvents:UIControlEventTouchUpInside];
        [_editBtn setTitle:@"修改订单" forState:UIControlStateNormal];
    }
    return _editBtn;
}
-(UIButton *)confirmBtn
{
    if (!_confirmBtn) {
        _confirmBtn = [UIButton new];
        _confirmBtn.width = WFCGFloatX(83.5);
        _confirmBtn.height = WFCGFloatY(25);
        _confirmBtn.x = self.view.width - WFCGFloatX(13 + 83.5);
        _confirmBtn.y = WFCGFloatY(11);
        [WFFunctions WFUIaddbordertoView:_confirmBtn radius:_confirmBtn.height / 2 width:0.7f color:Main_Color_Red];
        _confirmBtn.titleLabel.font = SYSTEMFONT(14);
        [_confirmBtn setTitleColor:Main_Color_Red forState:UIControlStateNormal];
        [_confirmBtn addTarget:self action:@selector(confirmBtnTap:) forControlEvents:UIControlEventTouchUpInside];
        [_confirmBtn setTitle:@"确认订单" forState:UIControlStateNormal];
    }
    return _confirmBtn;
}
-(UIButton *)evalBtn
{
    if (!_evalBtn) {
        _evalBtn = [UIButton new];
        _evalBtn.width = WFCGFloatX(83.5);
        _evalBtn.height = WFCGFloatY(25);
        _evalBtn.x = self.view.width - WFCGFloatX(13 + 83.5);
        _evalBtn.y = WFCGFloatY(11);
        [WFFunctions WFUIaddbordertoView:_evalBtn radius:_evalBtn.height / 2 width:0.7f color:Main_Color_Red];
        _evalBtn.titleLabel.font = SYSTEMFONT(14);
        [_evalBtn setTitleColor:Main_Color_Red forState:UIControlStateNormal];
        [_evalBtn addTarget:self action:@selector(evalBtnTap:) forControlEvents:UIControlEventTouchUpInside];
        [_evalBtn setTitle:@"提交评价" forState:UIControlStateNormal];
    }
    return _evalBtn;
}

-(UIView *)evalV
{
    if (!_evalV) {
        _evalV = [UIView new];
        _evalV.width = self.view.width;
        _evalV.height = WFCGFloatY(195);
        _evalV.backgroundColor = Main_Color_White;
        
        UILabel *titlelb = [UILabel new];
        titlelb.x = WFCGFloatX(13);
        titlelb.width = WFCGFloatX(60);
        titlelb.height = WFCGFloatY(51.5);
        titlelb.text = @"评分";
        titlelb.font = SYSTEMFONT(14);
        titlelb.textColor = Main_Color_Black;
        [_evalV addSubview:titlelb];
        [_evalV addSubview:self.starRatingView];
        [_evalV addSubview:self.evalReasonTV];
        
        UIView *sep = [UIView new];
        sep.y = WFCGFloatY(51.5);
        sep.width = self.view.width;
        sep.height = 0.7f;
        sep.backgroundColor = Main_Color_BG;
        [_evalV addSubview:sep];
    }
    self.starRatingView.value = _evalValue;
    return _evalV;
}
-(HCSStarRatingView *)starRatingView
{
    if (!_starRatingView) {
        _starRatingView = [[HCSStarRatingView alloc] initWithFrame:CGRectMake(WFCGFloatX(74), WFCGFloatY(15.5), WFCGFloatX(275), WFCGFloatY(20))];
        _starRatingView.maximumValue = 5;
        _starRatingView.minimumValue = 0;
        [_starRatingView addTarget:self action:@selector(didChangeValue:) forControlEvents:UIControlEventValueChanged];
        _starRatingView.emptyStarImage = [UIImage imageNamed:@"CommentStar"];
        _starRatingView.filledStarImage = [UIImage imageNamed:@"CommentStar_s"];
        [self.view addSubview:_starRatingView];
    }
    return _starRatingView;
}
-(UITextView *)evalReasonTV
{
    if (!_evalReasonTV) {
        _evalReasonTV = [UITextView new];
        _evalReasonTV.x = WFCGFloatX(13);
        _evalReasonTV.width = self.view.width - WFCGFloatX(26);
        _evalReasonTV.y = WFCGFloatY(64.5);
        _evalReasonTV.height = WFCGFloatY(130.5);
        _evalReasonTV.delegate = self;
        _evalReasonTV.font = SYSTEMFONT(14);
        _evalReasonTV.textColor = Main_Color_Gray;
        _evalReasonTV.text = _evalContent;
    }
    return _evalReasonTV;
}
-(GYMineOrderInfoDetailFootView *)orderFooterV
{
    if (!_orderFooterV) {
        _orderFooterV = [GYMineOrderInfoDetailFootView new];
    }
    GYMineOrderInfoDetailModel *model = self.viewModel.orderInfoDetailModel;
    _orderFooterV.dataModel = model;
    return _orderFooterV;
}
-(GYCancelOrderAlertView *)cancelAlertView
{
    if (!_cancelAlertView) {
        _cancelAlertView = [[GYCancelOrderAlertView alloc] init];
        _cancelAlertView.backgroundColor = [UIColor whiteColor];
        _cancelAlertView.frame = CGRectMake(0, 0, self.view.width, kGYCancelOrderAlertViewHeight);
        _cancelAlertView.delegate = self;
        [self.view addSubview:_cancelAlertView];
    }
    return _cancelAlertView;
}
#pragma mark - event
-(void)copyOrderTap:(id)sender
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.viewModel.orderInfoDetailModel.idField;
    [FTIndicator showToastMessage:@"复制成功!"];
}
-(void)cancelBtnTap:(id)sender
{
    //已下单  取消订单
    [self getCancelReason];
}
-(void)editBtnTap:(id)sender
{
    //修改订单
    GYMineOrderEditVC *edit = [GYMineOrderEditVC new];
    edit.viewModel = self.viewModel;
    [self.navigationController pushViewController:edit animated:YES];
}
-(void)confirmBtnTap:(id)sender
{
    //确认订单
    @WeakSelf;
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"确认之后不可更改哦~" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert showAlertViewWithCompleteBlock:^(NSInteger buttonIndex) {
        if (1 == buttonIndex) {
            NSMutableDictionary *para = [NSMutableDictionary new];
            NSString *orderid = [NSString stringWithFormat:@"%@",self.viewModel.orderInfoDetailModel.idField];
            [para setObject:orderid forKey:@"orderid"];
            [selfp.viewModel requestConfirm:para];
        }
    }];
}
-(void)evalBtnTap:(id)sender
{
    //评价订单
    if (_evalContent > 0) {
        NSMutableDictionary *para = [NSMutableDictionary new];
        NSString *orderid = [NSString stringWithFormat:@"%@",self.viewModel.orderInfoDetailModel.idField];
        NSString *grade = [NSString stringWithFormat:@"%ld",_evalValue];
        NSString *remark = [NSString stringWithFormat:@"%@",_evalContent];
        [para setObject:orderid forKey:@"orderid"];
        [para setObject:grade forKey:@"grade"];
        [para setObject:remark forKey:@"remark"];
        [self.viewModel requestEvalate:para];
    }else{
        [FTIndicator showErrorWithMessage:@"请输入评价内容！"];
    }
}
-(void)didChangeValue:(id)sender
{
    _evalValue = _starRatingView.value;
}
#pragma mark - method
-(void)initilization
{
    self.navigationItem.title = @"订单详情";
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.navigationController.navigationBar.shadowImage = [[UIImage new]rt_darkenWithLevel:0.3f];
    [self setNavgationTheme:1];
    self.isGroup = YES;
    [self.view addSubview:self.baseTable];
    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    [self.baseTable setSeparatorColor: Main_Color_BG];
    [self.baseTable setBackgroundColor:Main_Color_BG];
    [self.baseTable setTintColor:Main_Color_BG];
    self.baseTable.height = self.view.height - 64;
    self.baseTable.noDataBtn.hidden = YES;
    if (@available(iOS 11.0, *)) {
        //        self.baseTable.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
    }
    self.baseTable.mj_header.backgroundColor = Main_Color_Red;
    self.baseTable.scrollIndicatorInsets = self.baseTable.contentInset;
    
    //cancel
    [self.view addSubview:self.cancelAlertView];
    @WeakSelf;
    self.baseTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [selfp reloadData];
    }];
    
    [self.view addSubview:self.operateV];
    [self viewModelBand];
    _evalValue = 5;
    [self reloadData];
}
-(void)viewModelBand
{
    @WeakSelf;
    GCBaseObservationModel *observation = [GCBaseObservationModel new];
    observation.observation = self.viewModel;
    observation.keyPath = @"orderInfoDetailModel";
    observation.handler = ^(NSString *keyPath) {
        [selfp reloadView];
    };
    [self registObservation:observation];
    
    GCBaseObservationModel *observation1 = [GCBaseObservationModel new];
    observation1.observation = self.viewModel;
    observation1.keyPath = @"updateSign";
    observation1.handler = ^(NSString *keyPath) {
        [selfp.signalVC reloadFresh];
        [selfp.navigationController popViewControllerAnimated:YES];
    };
    [self registObservation:observation1];
}
-(void)reloadView
{
    [self.baseTable reloadData];
    [self.baseTable setTableFooterView:nil];
    
    if (1 == self.viewModel.orderInfoDetailModel.transtatus.integerValue) {
        //已下单
        self.operateV.hidden = NO;
        self.baseTable.height = WF_UI_VIEW_HEIGHT - self.bottomShelterHeight - self.operateV.height;
        if (0 == self.orderCatagery.integerValue) {
            //采购订单
            self.cancelBtn.x = self.view.width - WFCGFloatX(13 + 83.5);
            [WFFunctions WFUIaddbordertoView:_cancelBtn radius:_confirmBtn.height / 2 width:0.7f color:Main_Color_Red];
            [_cancelBtn setTitleColor:Main_Color_Red forState:UIControlStateNormal];
            self.cancelBtn.hidden = NO;
            self.editBtn.hidden = YES;
            self.confirmBtn.hidden = YES;
            self.evalBtn.hidden = YES;
        }else{
            //销售订单
            self.editBtn.x = self.view.width - WFCGFloatX(13 + 83.5 + 5 + 83.5 + 5 + 83.5);
            self.cancelBtn.x = self.view.width - WFCGFloatX(13 + 83.5 + 5 + 83.5);
            [WFFunctions WFUIaddbordertoView:_cancelBtn radius:_confirmBtn.height / 2 width:0.7f color:Main_Color_Black];
            [_cancelBtn setTitleColor:Main_Color_Black forState:UIControlStateNormal];
            self.confirmBtn.x = self.view.width - WFCGFloatX(13 + 83.5);
            self.cancelBtn.hidden = NO;
            self.editBtn.hidden = NO;
            self.confirmBtn.hidden = NO;
            self.evalBtn.hidden = YES;
        }
    }else if (2 == self.viewModel.orderInfoDetailModel.transtatus.integerValue) {
        //已完成或已评价
        self.operateV.hidden = NO;
        self.baseTable.height = WF_UI_VIEW_HEIGHT - self.bottomShelterHeight - self.operateV.height;
        if (0 == self.viewModel.orderInfoDetailModel.evalflag.integerValue) {
            //未评价
            if (0 == self.orderCatagery.integerValue) {
                //采购订单
                self.cancelBtn.hidden = YES;
                self.editBtn.hidden = YES;
                self.confirmBtn.hidden = YES;
                self.evalBtn.hidden = NO;
                [self.baseTable setTableFooterView:self.evalV];
            }else{
                //销售订单
                self.operateV.hidden = YES;
            }
        }else{
            //已评价
            self.operateV.hidden = YES;
            self.baseTable.height = WF_UI_VIEW_HEIGHT;
        }
    }else{
        self.operateV.hidden = YES;
        self.baseTable.height = WF_UI_VIEW_HEIGHT;
    }
}
-(void)reloadData
{
    [self.viewModel requestDetail];
}
-(void)getCancelReason
{
    [_cancelAlertView setTitleData:0 == self.orderCatagery.integerValue ? @[@"其他产品价格更低", @"操作有误", @"其他"] : @[@"产品已售完", @"其他"]];
    [_cancelAlertView pop];
    
//    NSString *title = @"取消原因";
//    NSString *hold1 = @"请输入取消原因";
//    TYAlertView *alertView = [TYAlertView alertViewWithTitle:title message:nil];
//    [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancel handler:^(TYAlertAction *action) {
//        NSLog(@"%@",action.title);
//    }]];
//    @WeakSelf;
//    [alertView addAction:[TYAlertAction actionWithTitle:@"确定" style:TYAlertActionStyleDestructive handler:^(TYAlertAction *action) {
//        UITextField *mintf = alertView.textFieldArray[0];
//        if (mintf.text.length > 0) {
//            NSString *min = mintf.text;
//            _cancelReason = min;
//            [selfp orderCancel];
//        }else{
//            [FTToastIndicator showToastMessage:@"请填写完整"];
//        }
//    }]];
//    
//    [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//        textField.placeholder = hold1;
//        textField.keyboardType = UIKeyboardTypeDefault;
//        [textField becomeFirstResponder];
//        textField.text = _cancelReason;
//    }];
//    
//    TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert];
//    
//    //alertController.alertViewOriginY = 60;
//    [self presentViewController:alertController animated:YES completion:nil];
}
-(void)orderCancel
{
    NSMutableDictionary *para = [NSMutableDictionary new];
    [para setObject:self.viewModel.orderInfoDetailModel.idField forKey:@"orderid"];
    [para setObject:_cancelReason forKey:@"cancelreason"];
    [self.viewModel requestCancel:para];
}
#pragma mark - life
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initilization];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - delegate
-(void)textViewDidEndEditing:(UITextView *)textView
{
    _evalContent = textView.text;
}
#pragma mark - GYCancelOrderAlertViewDelegate
- (void)cancelOrderView:(GYCancelOrderAlertView *)view reason:(NSString *)reason {
    _cancelReason = reason;
    [self orderCancel];
}
#pragma mark - table delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.viewModel.orderInfoDetailModel.productList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellID = @"CellID";
    GYMineOrderInfoListModel *model = self.viewModel.orderInfoDetailModel.productList[indexPath.row];
    GYMineOrderInfoListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[GYMineOrderInfoListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
    }
    cell.model = model;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = [GYMineOrderInfoListCell finalHeight];
    return height;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIImageView *view = [UIImageView new];
    view.width = self.view.width;
    view.height = WFCGFloatY(45);
    view.backgroundColor = Main_Color_White;
    view.userInteractionEnabled = YES;
    
    UIView *sign = [UIView new];
    sign.backgroundColor = Main_Color_Red;
    sign.frame = WFCGRectMake(13, 16.5, 5, 15);
    sign.centerY = view.centerY;
    [view addSubview:sign];
    
    UILabel *titlelb = [UILabel new];
    titlelb.x = WFCGFloatX(23);
    titlelb.width = self.view.width - WFCGFloatX(26);
    titlelb.height = WFCGFloatY(34);
    titlelb.centerY = view.centerY;
    titlelb.font = SYSTEMFONT(15);
    titlelb.textColor = Main_Color_Black;
    GYMineOrderInfoDetailModel *info = self.viewModel.orderInfoDetailModel;
    titlelb.text = info.companyname;
    [view addSubview:titlelb];
    
    UIButton *phonenumbtn = [UIButton new];
    phonenumbtn.x = WFCGFloatX(234);
    phonenumbtn.width = WFCGFloatX(100);
    phonenumbtn.height = WFCGFloatX(16.5);
    phonenumbtn.centerY = view.centerY;
    phonenumbtn.titleLabel.font = SYSTEMFONT(12);
    [phonenumbtn setTitle:info.mobile forState:UIControlStateNormal];
    [phonenumbtn setTitleColor:Main_Color_Gray forState:UIControlStateNormal];
    [phonenumbtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        [[GCPresenter shareInterface]phoneCall:info.mobile];
    }];
    [phonenumbtn setEnlargeEdge:10];
    [view addSubview:phonenumbtn];
    
    UIButton *phonesign = [UIButton new];
    phonesign.x = WFCGFloatX(340);
    phonesign.width = WFCGFloatX(14.5);
    phonesign.height = WFCGFloatX(14.5);
    phonesign.centerY = view.centerY;
    [phonesign setBackgroundImage:[UIImage imageNamed:@"phone"] forState:UIControlStateNormal];
    //phonesign.backgroundColor = Main_Color_Blue;
    [phonesign handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        [[GCPresenter shareInterface]phoneCall:info.mobile];
    }];
    [phonesign setEnlargeEdge:10];
    [view addSubview:phonesign];
    
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return WFCGFloatY(44.5);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return self.orderFooterV;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return self.orderFooterV.height;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    GYMineOrderInfoListModel *model = self.viewModel.orderInfoDetailModel.productList[indexPath.row];
    GYHomeSaleDetailVC *detail = [[GYHomeSaleDetailVC alloc] init];
    detail.passID = [NSString stringWithFormat:@"%ld",model.proid];
    [self.navigationController pushViewController:detail animated:YES];
}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
